import {
  CoolController,
  BaseController,
  CoolUrlTag,
  TagTypes,
  CoolTag,
} from '@cool-midway/core';
import { Body, Get, Inject, Post, Provide, Query } from '@midwayjs/core';
import { BizCustomerWorkerCollectionEntity } from '../../entity/workerCollection';
import { BizCustomerWorkerCollectionService } from '../../service/workerCollection';

/**
 * app相关接口
 */
@CoolUrlTag()
@CoolController({
  api: ['add', 'delete', 'page'],
  entity: BizCustomerWorkerCollectionEntity,
  service: BizCustomerWorkerCollectionService,
  pageQueryOp: {
    fieldEq: ['id'],
    keyWordLikeFields: [],
  },
})
export class BizCustomerWorkerCollectionAppController extends BaseController {
  @Inject()
  bizCustomerWorkerCollectionService: BizCustomerWorkerCollectionService;

  @Post('/pageAndWorkerInfo', { summary: '收藏师傅列表分页接口' })
  async pageAndWorkerInfo(
    @Body('page') page,
    @Body('size') size,
    @Body('userId') userId
  ) {
    return this.ok(
      await this.bizCustomerWorkerCollectionService.pageAndWorkerInfo(
        page,
        size,
        userId
      )
    );
  }

  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Get('/checkCollection', { summary: '判断是否收藏师傅' })
  async checkCollection(@Query('userId') userId, @Query('workerId') workerId) {
    return this.ok(
      await this.bizCustomerWorkerCollectionService.checkCollection(
        userId,
        workerId
      )
    );
  }

  @Post('/collection', { summary: '收藏&取消收藏' })
  async collection(@Body('userId') userId, @Body('workerId') workerId) {
    return this.ok(
      await this.bizCustomerWorkerCollectionService.collection(userId, workerId)
    );
  }
}
